import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;


public class SendMess {
	String msg = null;
	MulticastSocket s = null;
	InetAddress group = null;

	public SendMess(MulticastSocket s, InetAddress group) {
		this.s = s;
		this.group = group;
		try {
			s.setTimeToLive(255);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void send() {
		try {
			msg = ("javaplus	" + "说：" + "你妹你妹你妹");
			DatagramPacket data = new DatagramPacket(
					msg.getBytes(), msg.getBytes().length, group,
					6789);
			s.send(data);
		} catch (IOException e1) {
			System.out.println("发送失败");
		}
	}

	public static void main(String[] args) throws IOException {
		MulticastSocket s;
		InetAddress group = InetAddress.getByName("228.9.6.132");
		s = new MulticastSocket(6789);
		s.joinGroup(group);
		
		final SendMess sendMess = new SendMess(s, group);
		new Thread(){
			public void run() {
				while(true) {
					sendMess.send();
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
		}.start();
	}
}